//
//  SLCommonsFileUtility.m
//  SecretRoom
//
//  Created by Sitdhibhong Laokok on 9/7/54 BE.
//  Copyright 2554 App Tree. All rights reserved.
//

#import "SLCommonsFileUtility.h"

#import "Evidence.h"
#import "Event.h"

@implementation SLCommonsFileUtility

@synthesize event;
@synthesize evidence;

- (id)init
{
    self = [super init];
    if (self) {
        // Initialization code here.
    }
    
    return self;
}

- (id)initWitEvidence:(Evidence *)evd inEvent:(Event *)evt
{
    if (self = [super init]) {
        self.event = evt;
        self.evidence = evd;
    }
    
    return self;
}

+ (NSString *)categoryFromEvent:(Event *)evt
{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat = @"yyyyMMddHHmm";
    
    NSString *timestamp = [NSString stringWithFormat:@"%@.%@",[evt.eventName stringByReplacingOccurrencesOfString:@" " withString:@""], [formatter stringFromDate:evt.eventTimestamp]];
    [formatter release];
    
    return timestamp;
}

+ (NSString *)categoryLongFormatWithEvent:(Event *)evt
{
    return [[SLCommonsFileUtility shortHandForDocumentPath] stringByAppendingPathComponent:[SLCommonsFileUtility categoryFromEvent:evt]];
}

+ (NSString *)shortHandForDocumentPath
{
    return [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
}

+ (NSString *)evidenceURLResolvedWithEvidence:(Evidence *)evd inEvent:(Event *)evt
{
    NSLog(@"%s: %@, %@", __PRETTY_FUNCTION__, evd, evt);
//    return [[[SLCommonsFileUtility shortHandForDocumentPath] stringByAppendingPathComponent:[SLCommonsFileUtility categoryFromEvent:evt]] stringByAppendingPathComponent:evd.localUrl];
    
    return [[SLCommonsFileUtility shortHandForDocumentPath] stringByAppendingFormat:@"%@", evd.localUrl];
}

- (void)dealloc 
{
    [event release];
    [evidence release];
    
    [super dealloc];
}

@end
